package com.example.demo.service;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @Author: FKJGFK
 * @Date: 2021/5/7 14:04
 * @Description:
 */
@Slf4j
@Component
public class KafkaConsumerTest {

    @KafkaListener(topics = {"11"})
    public void listen(ConsumerRecord<?, ?> record) {

        Optional<?> kafkaMessage = Optional.ofNullable(record.value());

        if (kafkaMessage.isPresent()) {

            Object message = kafkaMessage.get();
            log.info("------------------ message =" + message);
        }

    }
}
